
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:my_app/conponate/user_info.dart';
import 'package:my_app/tools/http_server.dart';
import 'star_rubbish_listtile.dart';


class StarRubbishs extends StatefulWidget {

  const StarRubbishs({Key? key}) : super(key: key);

  @override
  _StarRubbishsState createState() => _StarRubbishsState();
}

class _StarRubbishsState extends State<StarRubbishs> with TickerProviderStateMixin{
  bool isChanged = false;
  late AnimationController _controller;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _controller = AnimationController(vsync: this,
        duration: Duration(seconds: 1));
  }

  @override
  Widget build(BuildContext context) {

    Future<Null> _onRefresh(){
      return Future.delayed(Duration(seconds: 5),(){   // 延迟5s完成刷新
        setState(() {
          // itemCount = 10;
        });
      });
    }

  return Scaffold(
      appBar: (
          AppBar(
            backgroundColor: Colors.blueGrey,
            title: Text(
              "收藏",
            ),
            centerTitle: true,
            elevation: 5.0,
          )
      ),
      body: FutureBuilder(
        future: HttpServer.getStar(UserInfo.userName),
        builder: (BuildContext context, AsyncSnapshot<List> snapshot){
          if(snapshot.connectionState == ConnectionState.done){
            if(snapshot.hasError){
              return Text("error");
            }else{
              var data = snapshot.data;
              print("data: $data");
              List<Map<String, dynamic>> tiles = (data as List).cast();
              print("tiles: ${tiles.length}");
              return ListView.builder(
                  itemCount: tiles.length,
                  shrinkWrap: true,
                  itemBuilder: (BuildContext context, int index) {
                    return StarListTile(
                      gname:'${(tiles)[index]["gname"]}',
                      type: '${(tiles)[index]["type"]}');
                  }
              );
            }
          } else{
            return Align(
              child: CircularProgressIndicator(),
              alignment: Alignment.center,
            );
          }
        },
      ),
    );
  }
}
